package jpa4azure.impl;

import java.lang.reflect.Method;

import com.windowsazure.samples.table.AzureTableEntity;

import jpa4azure.type.Key;
import jpa4azure.type.TypeWrapperFactory;

public class LoadFieldOperation {
	Method method;
	AzureEntityManager aem;

	public LoadFieldOperation(Method method,  AzureEntityManager aem) {
		this.method = method;
		this.aem = aem;
	}

	public Object get(Key key) {	
		Class<?> c = method.getReturnType();
		String table = TypeWrapperFactory.wrap(c).getTableName();
		AzureTableEntity e = aem.getTableStorageClient().getEntity(table, key.getPartition(), key.getRow());
		return aem.convert(e);
	}
}
